package com.yuanheng100.ems4j.mapper;

import com.yuanheng100.ems4j.model.Ems4jEmployee;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.LinkedList;
import java.util.List;

public interface Ems4jEmployeeMapper
{

    /**
     * 查询userid对应的Ems4jEmployee
     *
     * @param userid
     * @return
     */
    @Select({
            "SELECT",
            "userid, name, department, mobile, email, position, password, idcardno, entrydate, ",
            "deletedate, empstatus, appids, weixinid, weixinavatarmediaid, dingtel, dingworkplace, ",
            "dingjobnumber, dingissenior, dingisleaderindepts",
            "FROM ems4j_employee",
            "WHERE userid = #{userid,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column = "userid", property = "userid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "department", property = "department", jdbcType = JdbcType.INTEGER),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.BIGINT),
            @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR),
            @Result(column = "position", property = "position", jdbcType = JdbcType.VARCHAR),
            @Result(column = "password", property = "password", jdbcType = JdbcType.CHAR),
            @Result(column = "idcardno", property = "idcardno", jdbcType = JdbcType.CHAR),
            @Result(column = "entrydate", property = "entrydate", jdbcType = JdbcType.DATE),
            @Result(column = "deletedate", property = "deletedate", jdbcType = JdbcType.DATE),
            @Result(column = "empstatus", property = "empstatus", jdbcType = JdbcType.SMALLINT),
            @Result(column = "appids", property = "appids", jdbcType = JdbcType.VARCHAR),
            @Result(column = "weixinid", property = "weixinid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "weixinavatarmediaid", property = "weixinavatarmediaid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingtel", property = "dingtel", jdbcType = JdbcType.INTEGER),
            @Result(column = "dingworkplace", property = "dingworkplace", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingjobnumber", property = "dingjobnumber", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingissenior", property = "dingissenior", jdbcType = JdbcType.SMALLINT),
            @Result(column = "dingisleaderindepts", property = "dingisleaderindepts", jdbcType = JdbcType.VARCHAR)
    })
    Ems4jEmployee selectByPrimaryKey(Integer userid);

    @Select({
            "SELECT",
            "userid, name, department, mobile, email, position, password, idcardno, entrydate, ",
            "deletedate, empstatus, appids, weixinid, weixinavatarmediaid, dingtel, dingworkplace, ",
            "dingjobnumber, dingissenior, dingisleaderindepts",
            "FROM ems4j_employee",
            "WHERE mobile = #{mobile,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "userid", property = "userid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "department", property = "department", jdbcType = JdbcType.INTEGER),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.BIGINT),
            @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR),
            @Result(column = "position", property = "position", jdbcType = JdbcType.VARCHAR),
            @Result(column = "password", property = "password", jdbcType = JdbcType.CHAR),
            @Result(column = "idcardno", property = "idcardno", jdbcType = JdbcType.CHAR),
            @Result(column = "entrydate", property = "entrydate", jdbcType = JdbcType.DATE),
            @Result(column = "deletedate", property = "deletedate", jdbcType = JdbcType.DATE),
            @Result(column = "empstatus", property = "empstatus", jdbcType = JdbcType.SMALLINT),
            @Result(column = "appids", property = "appids", jdbcType = JdbcType.VARCHAR),
            @Result(column = "weixinid", property = "weixinid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "weixinavatarmediaid", property = "weixinavatarmediaid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingtel", property = "dingtel", jdbcType = JdbcType.INTEGER),
            @Result(column = "dingworkplace", property = "dingworkplace", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingjobnumber", property = "dingjobnumber", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingissenior", property = "dingissenior", jdbcType = JdbcType.SMALLINT),
            @Result(column = "dingisleaderindepts", property = "dingisleaderindepts", jdbcType = JdbcType.VARCHAR)
    })
    Ems4jEmployee selectByMobile(Long mobile);

    @Select({
            "SELECT",
            "userid, name, department, mobile, email, position, password, idcardno, entrydate, ",
            "deletedate, empstatus, appids, weixinid, weixinavatarmediaid, dingtel, dingworkplace, ",
            "dingjobnumber, dingissenior, dingisleaderindepts",
            "FROM ems4j_employee",
            "WHERE email = #{email,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "userid", property = "userid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "department", property = "department", jdbcType = JdbcType.INTEGER),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.BIGINT),
            @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR),
            @Result(column = "position", property = "position", jdbcType = JdbcType.VARCHAR),
            @Result(column = "password", property = "password", jdbcType = JdbcType.CHAR),
            @Result(column = "idcardno", property = "idcardno", jdbcType = JdbcType.CHAR),
            @Result(column = "entrydate", property = "entrydate", jdbcType = JdbcType.DATE),
            @Result(column = "deletedate", property = "deletedate", jdbcType = JdbcType.DATE),
            @Result(column = "empstatus", property = "empstatus", jdbcType = JdbcType.SMALLINT),
            @Result(column = "appids", property = "appids", jdbcType = JdbcType.VARCHAR),
            @Result(column = "weixinid", property = "weixinid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "weixinavatarmediaid", property = "weixinavatarmediaid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingtel", property = "dingtel", jdbcType = JdbcType.INTEGER),
            @Result(column = "dingworkplace", property = "dingworkplace", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingjobnumber", property = "dingjobnumber", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingissenior", property = "dingissenior", jdbcType = JdbcType.SMALLINT),
            @Result(column = "dingisleaderindepts", property = "dingisleaderindepts", jdbcType = JdbcType.VARCHAR)
    })
    Ems4jEmployee selectByEmail(String email);

    /**
     * 增加Ems4jEmployee记录
     *
     * @param record
     * @return
     */
    @Insert({
            "INSERT INTO ems4j_employee (userid, name, ",
            "department, mobile, ",
            "email, position, ",
            "password, idcardno, entrydate, ",
            "deletedate, empstatus, ",
            "appids, weixinid, ",
            "weixinavatarmediaid, dingtel, ",
            "dingworkplace, dingjobnumber, ",
            "dingissenior, dingisleaderindepts)",
            "VALUES (#{userid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
            "#{department,jdbcType=INTEGER}, #{mobile,jdbcType=BIGINT}, ",
            "#{email,jdbcType=VARCHAR}, #{position,jdbcType=VARCHAR}, ",
            "#{password,jdbcType=CHAR}, #{idcardno,jdbcType=CHAR}, #{entrydate,jdbcType=DATE}, ",
            "#{deletedate,jdbcType=DATE}, #{empstatus,jdbcType=SMALLINT}, ",
            "#{appids,jdbcType=VARCHAR}, #{weixinid,jdbcType=VARCHAR}, ",
            "#{weixinavatarmediaid,jdbcType=VARCHAR}, #{dingtel,jdbcType=INTEGER}, ",
            "#{dingworkplace,jdbcType=VARCHAR}, #{dingjobnumber,jdbcType=VARCHAR}, ",
            "#{dingissenior,jdbcType=SMALLINT}, #{dingisleaderindepts,jdbcType=VARCHAR})"
    })
    int insert(Ems4jEmployee record);

    /**
     * 更新Ems4jEmployee记录
     *
     * @param record
     * @return
     */
    @Update({
            "UPDATE ems4j_employee",
            "SET name = #{name,jdbcType=VARCHAR},",
            "department = #{department,jdbcType=INTEGER},",
            "mobile = #{mobile,jdbcType=BIGINT},",
            "email = #{email,jdbcType=VARCHAR},",
            "position = #{position,jdbcType=VARCHAR},",
            "password = #{password,jdbcType=CHAR},",
            "idcardno = #{idcardno,jdbcType=CHAR},",
            "entrydate = #{entrydate,jdbcType=DATE},",
            "deletedate = #{deletedate,jdbcType=DATE},",
            "empstatus = #{empstatus,jdbcType=SMALLINT},",
            "appids = #{appids,jdbcType=VARCHAR},",
            "weixinid = #{weixinid,jdbcType=VARCHAR},",
            "weixinavatarmediaid = #{weixinavatarmediaid,jdbcType=VARCHAR},",
            "dingtel = #{dingtel,jdbcType=INTEGER},",
            "dingworkplace = #{dingworkplace,jdbcType=VARCHAR},",
            "dingjobnumber = #{dingjobnumber,jdbcType=VARCHAR},",
            "dingissenior = #{dingissenior,jdbcType=SMALLINT},",
            "dingisleaderindepts = #{dingisleaderindepts,jdbcType=VARCHAR}",
            "WHERE userid = #{userid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Ems4jEmployee record);

    /**
     * 根据 depId  roleId  status获取对应的员工
     *
     * @param depId
     * @param roleId
     * @param status
     * @return
     */
    @SelectProvider(type = Ems4jEmployeeSQLProvider.class, method = "selectEmployeeListByDepIdRoleIdStatus")
    LinkedList<Ems4jEmployee> selectEmployeeListByDepIdRoleIdStatus(@Param("depId") int depId, @Param("roleId") int roleId, @Param("status") short status);

    /**
     * 获取所有的员工
     *
     * @return
     */
    @Select({
            "SELECT",
            "userid, name, department, mobile, email, position, password, idcardno, entrydate, ",
            "deletedate, empstatus, appids, weixinid, weixinavatarmediaid, dingtel, dingworkplace, ",
            "dingjobnumber, dingissenior, dingisleaderindepts",
            "FROM ems4j_employee"
    })
    @Results({
            @Result(column = "userid", property = "userid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "department", property = "department", jdbcType = JdbcType.INTEGER),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.BIGINT),
            @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR),
            @Result(column = "position", property = "position", jdbcType = JdbcType.VARCHAR),
            @Result(column = "password", property = "password", jdbcType = JdbcType.CHAR),
            @Result(column = "idcardno", property = "idcardno", jdbcType = JdbcType.CHAR),
            @Result(column = "entrydate", property = "entrydate", jdbcType = JdbcType.DATE),
            @Result(column = "deletedate", property = "deletedate", jdbcType = JdbcType.DATE),
            @Result(column = "empstatus", property = "empstatus", jdbcType = JdbcType.SMALLINT),
            @Result(column = "appids", property = "appids", jdbcType = JdbcType.VARCHAR),
            @Result(column = "weixinid", property = "weixinid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "weixinavatarmediaid", property = "weixinavatarmediaid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingtel", property = "dingtel", jdbcType = JdbcType.INTEGER),
            @Result(column = "dingworkplace", property = "dingworkplace", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingjobnumber", property = "dingjobnumber", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dingissenior", property = "dingissenior", jdbcType = JdbcType.SMALLINT),
            @Result(column = "dingisleaderindepts", property = "dingisleaderindepts", jdbcType = JdbcType.VARCHAR)
    })
    List<Ems4jEmployee> selectAllEmployees();

    @Update({
            "UPDATE ems4j_employee",
            "SET department = #{toDepartmentId,jdbcType=INTEGER}",
            "WHERE department = #{fromDepartmentId,jdbcType=INTEGER}"
    })
    int transferEmployee(@Param("fromDepartmentId") Integer fromDepartmentId, @Param("toDepartmentId") Integer toDepartmentId);
}